﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using daSyntaxAnalyser.SyntaxTree;

namespace CQLQueries.SyntaxTree
{
    public class FactorNode
    {
        public object NodeTree;
        public object ValueUp;

        public ExpressionNode Expression;
        public FactorNode Factor;
        public ConstNode Const;
        public IdNode Id;

        public FactorNode()
        {            
        }

        public void Visit()
        {
            if (Expression != null)
            {
                Expression.NodeTree = NodeTree;
                Expression.Visit();
                ValueUp = Expression.ValueUp;
            }
            else if (Factor != null)
            {
                Factor.NodeTree = NodeTree;
                Factor.Visit();
                ValueUp = -Convert.ToDouble(Factor.ValueUp);
            }
            else if (Const != null)
            {
                ValueUp = Const.ValueUp;
            }
            else
            {
                ValueUp = Id.ValueUp;
            }
        }
    }
}
